import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RefineryUtilities;


public class Charts extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Charts(String appTitle, double[] values){
		super(appTitle);
		
		final CategoryDataset dataset = createDataset(values);
        final JFreeChart chart = createChart(dataset);

        // add the chart to a panel...
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);
		
		
	}

	private CategoryDataset createDataset(double[] values) {
		DefaultCategoryDataset dataSet = new  DefaultCategoryDataset();
		dataSet.addValue(values[0], (Integer)0, (String)"yes");
		dataSet.addValue(values[1], (Integer)1, (String)"no");
		return dataSet;
	}

	private JFreeChart createChart(final CategoryDataset dataset) {
		final JFreeChart chart = ChartFactory.createBarChart3D(
	            "Verteilung der Werte",      // chart title
	            "Conversation",               // domain axis label
	            "Probability",                  // range axis label
	            dataset,                  // data
	            PlotOrientation.VERTICAL, // orientation
	            false,                     // include legend
	            true,                     // tooltips
	            false                     // urls
	        );

	        final CategoryPlot plot = chart.getCategoryPlot();
	        final CategoryAxis axis = plot.getDomainAxis();
	        axis.setCategoryLabelPositions(
	            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)
	        );
	        final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
	        renderer.setDrawBarOutline(false);
	        
	        return chart;
	}
	
	public void start(){
		this.pack();
		RefineryUtilities.centerFrameOnScreen(this);
        this.setVisible(true);
		
	}
}
